package mp

import (
	"duoke/model"
	"duoke/service"
	"duoke/utils/gconv"
	"duoke/utils/request"
	"duoke/utils/response"
	"github.com/gin-gonic/gin"
)

var CourseShare = new(courseShareCtl)

type courseShareCtl struct{}

func (ctl *courseShareCtl) Save(c *gin.Context) {
	req := request.JsonMap(c)
	id := gconv.Int(req["id"])
	share_type := gconv.Int(req["share_type"])
	if id == 0 || share_type == 0 {
		response.Error(c, "参数缺失【id/share_type】", nil)
		return
	}
	err := service.CourseShare.Save(c, id, share_type)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", nil)
}
func (ctl *courseShareCtl) List(c *gin.Context) {
	var req model.CourseShareListReq
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	list, total, err := service.CourseShare.List(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "获取成功", gin.H{"total": total, "list": list})
}
